package com.itboye.textileexpes.presenter;

import java.util.List;
import java.util.Observer;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.ForresterBeans;
import com.itboye.textileexpes.beans.GoodsBean;
import com.itboye.textileexpes.beans.GoodsSearch;
import com.itboye.textileexpes.interfaces.ICategory;
import com.itboye.textileexpes.interfaces.IGoods;
import com.itboye.textileexpes.repository.CategoryRepository;
import com.itboye.textileexpes.repository.GoodsRepository;
import com.itboye.textileexpres.base.BasePresenter;
import com.itboye.textileexpres.base.ResultEntity;

public class GoodsPresenter extends BasePresenter implements IGoods<GoodsBean> {
	public static final String Fenye_success = MainPresenter.class.getName()
			+ "_Fenye_success";
	public static final String Fenye_fail = MainPresenter.class.getName()
			+ "_Fenye_fail";
	public static final String Keyword_success = MainPresenter.class.getName()
			+ "_Keyword_success";
	public static final String Keyword_fail = MainPresenter.class.getName()
			+ "_Keyword_fail";
	public static final String Detail_success = MainPresenter.class.getName()
			+ "_Detail_success";
	public static final String Detail_fail = MainPresenter.class.getName()
			+ "_Detail_fail";
	public static final String Top_success = MainPresenter.class.getName()
			+ "_Top_success";
	public static final String Top_fail = MainPresenter.class.getName()
			+ "_Top_fail";

	public GoodsPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(GoodsBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(GoodsBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(GoodsBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getInfo(GoodsBean model) {
		// TODO Auto-generated method stub
		IGoods<GoodsBean> goods = new GoodsRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Fenye_success);
				setChanged();
				notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Fenye_fail);
				setChanged();
				notifyObservers(result);

			}
		});
		goods.getInfo(model);
	}

	@Override
	public List<GoodsBean> query(GoodsBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void keyWordQuery(String key) {
		// TODO Auto-generated method stub
		IGoods<GoodsBean> goods = new GoodsRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Keyword_success);
				setChanged();
				notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Keyword_fail);
				setChanged();
				notifyObservers(result);

			}
		});
		goods.keyWordQuery(key);
	}

	@Override
	public void DetailQuery(String pid) {
		// TODO Auto-generated method stub
		IGoods<GoodsBean> goods = new GoodsRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Detail_success);
				setChanged();
				notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Detail_fail);
				setChanged();
				notifyObservers(result);

			}
		});
		goods.DetailQuery(pid);
	}

	@Override
	public void AllQuery(String uid, String pageindex, String pagesize) {
		// TODO Auto-generated method stub
		IGoods<GoodsBean> goods = new GoodsRepository(new ICompleteListener() {

			@Override
			public void success(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Top_success);
				setChanged();
				notifyObservers(result);
			}

			@Override
			public void failure(ResultEntity result) {
				// TODO Auto-generated method stub
				result.setEventTag(Tag_Success);
				result.setEventType(Top_fail);
				setChanged();
				notifyObservers(result);

			}
		});
		goods.AllQuery(uid, pageindex, pagesize);
	}

	@Override
	public void serarchQuery(GoodsSearch s) {
		// TODO Auto-generated method stub

	}

	@Override
	public void typeQuery(GoodsSearch s) {
		// TODO Auto-generated method stub

	}

}
